How can we help you today?

How to Dynamically Set a Current Date (Day, Month, Year) in ShortPoint Footer or Design Elements

In this article, we will show you how to set a current date (day, month, year) dynamically so that you won't need to update it manually. 


Before
After
Footer
Static year in the ShortPoint footerDynamic year in the ShortPoint footer
Design Element
Static date in the ShortPoint Design ElementDynamic date in the ShortPoint Design Element

TABLE OF CONTENTS


This article is for you if

  • You have ShortPoint installed on your SharePoint sites(s).
  • You are a ShortPoint user with an active license.

Supported platforms

  • SharePoint 2013
  • SharePoint 2016 
  • SharePoint 2019
  • Office 365 (SharePoint Online)


You can add the data attribute to both a footer and a Design Element on a specific SharePoint page. Feel free to choose the relevant option, based on your needs.


Create the ShortPoint footer in the Generator. You can build it from scratch, or use a footer template from the Demo Pages.


New Footer in the ShortPoint Generator


Click the cog wheel icon to open the settings of the Column, where you would like to display the date/year dynamically.


Cog wheel icon to open the Settings of the Column


Switch to the Content tab and enable the code view:


Content tab and code view option highlighted


Wrap the text into a <span> tag. Add a data attribute with the value true to this tag, for example:

<span data-year="true">2020</span>


Adding data-year attribute


Idea: If you'd like to set a month/day, you might want to give the attribute a relevant name, for example, data-month or data-today. The value should still be set to true.


Click Update to save the changes:


Update button


Scroll down a bit and click Save Changes to update the footer:


Save Changes button for the footer


  • In the Design Element



Before we start: If you are using ShortPoint SPFx version 7.3.x.xx+ on Office 365 or SharePoint 2019 environment, you might want to use the TODAY or Now data placeholders (if you'd like to display the current date/time in your Design Element). You will be able to use it in any text field, including Design Element's titles, subtitles etc. To know more about the placeholders, continue to our solution article: How To Use Placeholders In ShortPoint Connections.



Add a Design Element that you would like to update the text for. For the purpose of this article, we will use the Alert Design Element, to display the today's urgent tasks list.


Alert Design Element selected from the Page Builder


Idea: Inside the Alert, we have added the title text with some random date inside, and the Simple Lists Design Element, dynamically connected to a SharePoint list that stores the tasks list, Today's tasks view:


Alert Design Element with Text and Simple Lists Design Element inside

To know more about the ShortPoint Connect feature, check our ShortPoint Connect: Basic Tutorial.


Click the cog wheel icon to open the settings of the Column, where you have your Design Element with the text to display the date/year dynamically:


Cog wheel icon to open the Settings of the Column


Switch to the Content tab and enable the code view:


Content tab and code view option highlighted


Wrap the text into a <span> tag. Add a data attribute with the value true to this tag, for example:

<span data-today="true">01/03/2021</span>


Adding data-today attribute


Idea: If you'd like to set a month/day, you might want to give the attribute a relevant name, for example, data-month or data-year. The value should still be set to true.


Click Update to save the changes:


Update button


Save/publish the page.


Step 2. Add a custom JavaScript code in Theme Builder


Open ShortPoint Theme Builder.


Navigate to Utilities > Custom JavaScript:


Theme Builder > UtilitiesUtilties > Custom JavaScript


Based on your needs, copy one of the following JavaScript codes, or prepare your own, if you'd like to display other date/time properties on your page/footer:


  • Option 1. To display the current year

Please use this code:


document.querySelector('[data-year="true"]').innerText = ( new Date().getFullYear() );



Note: Do not forget to update the data attribute name in case you have a different one.

  • Option 2. To display the today's date


The today's date will be displayed in the MM/DD/YYYY format (e.g., 03/01/2021):


var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();
today = mm + '/' + dd + '/' + yyyy;

document.querySelector('[data-today="true"]').innerText = today;



Notes: 
1. Do not forget to update the data attribute name in case you have a different one. 2. If you need another format, make sure to modify the today variable, and other parts if required. For example, to display the date in DD/MM/YYYY format, it should look like this:
today = dd + '/' + mm + '/' + 'yyyy';

Paste it to the Custom JavaScript field:


Code pasted to Custom JavaScript text area


Click Apply (1), and then Publish (2) to save your customizations.


Apply and Publish buttons highlighted


Result


That's it. Now, the date (year, month, day) will update automatically in your footer or Design Element based on the applied settings.



Dynamic year in the ShortPoint footer


  • In the Design Element


Dynamic date in the ShortPoint Design Element


Related articles:

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.

World's best intranet sites are designed using ShortPoint

Get started today! Learn more
See all 15 topics

Start a trial

Ignite your vision. Install ShortPoint directly on your site, or play in sandbox mode. No credit card required.

Get started today

World’s best intranet sites are designed using ShortPoint

Thousands of companies using ShortPoint everyday to design, brand and build award winning intranet sites.

Get started Learn more